package com.haida.translation_web.strategymodel;

import com.haida.translation_web.trans.AbstractTranslator;
import com.haida.translation_web.trans.impl.BaiduTranslator;
import com.haida.translation_web.trans.impl.GoogleTranslator;
import com.haida.translation_web.trans.impl.YoudaoTranslator;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author LHJ_Jack
 * @Description TODO
 * @Date 2021/05/29 星期六 20:06
 */
@Component
public class StrategyFactory {
    private static final Map<String, AbstractTranslator> strategies = new HashMap<>();

    static {
        strategies.put("Baidu", new BaiduTranslator());
        strategies.put("Google", new GoogleTranslator());
        strategies.put("Youdao", new YoudaoTranslator());
    }

    public static AbstractTranslator getStrategy(String type) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        return strategies.get(type);
    }

    public static Map<String, AbstractTranslator> getStrategies() {
        return strategies;
    }
}

